﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using NetJsWire.Lite.Converters;
using Newtonsoft.Json;

namespace NetJsWire.Lite.Widgets.UI.Form
{
    public class LabelLW : BoxComponent
    {
        public LabelLW()
        {
        }

        public LabelLW( IContainer container )
        {
            container.Add( this );
        }

        [Browsable( true ), EditorBrowsable( EditorBrowsableState.Always ), DefaultValue( ( string ) null )]
        [JsonProperty( "text", DefaultValueHandling = DefaultValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore )]
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        public override Color BackColor
        {
            get
            {
                return Parent != null ? Parent.BackColor : Color.Transparent;
            }
            set { }
        }

        [DefaultValue( "label" )]
        [TypeConverter( typeof( XtypeTypeConverter ) )]
        public override string Xtype
        {
            get
            {
                return "label";
            }
            set { }
        }

        protected override void OnPaint( PaintEventArgs e )
        {
            //base.OnPaint( e );
            using ( var font = new Font( "Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel ) )
            {
                using ( var br = new SolidBrush( Color.Black ) )
                {
                    //var textSize = e.Graphics.MeasureString( ":", font );
                    e.Graphics.DrawString( Text, font, br, 0, 0 );
                }
            }
        }
    }
}